package com.base.system.managedBean;

import java.util.Map;

import javax.faces.context.FacesContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.user.util.Browser;

import com.base.commons.SpringBeanHolder;
import com.base.organization.entity.CentralUnit;
import com.base.organization.service.ICentralUnitDAO;
import com.base.security.SecurityConst;
import com.base.system.managedBean.baseBean.BaseCentralUnitBean;

/**
 * 
 * This managed bean is generated automatically
 */
@ManagedBean(name = "system_editCentralUnitBean", scope = ManagedBeanScope.REQUEST)
public class EditCentralUnitBean extends BaseCentralUnitBean {
	Log logger = LogFactory.getLog(EditCentralUnitBean.class);
	private ICentralUnitDAO centralUnitDAO = SpringBeanHolder
			.getBean("centralUnitDAO");
	@Inject
	private FacesContext context;

	protected void initSpecialProperty() {
		Map<String, Object> session = context.getExternalContext()
				.getSessionMap();
		centralUnit = (CentralUnit) session
				.get(SecurityConst.CENTRALUNIT_SELECT_ROW_DATA);
		this.getCentralUnitProperty();
	}

	@BeforeRender
	public void beforeRender(boolean isPostback) {
		if (!isPostback) {
			this.initSpecialProperty();
		}
	}

	@Action(id = "saveCentralUnit")
	public void saveCentralUnit() {
		centralUnit = centralUnitDAO.get(Integer.parseInt(centralUnitId));
		setCentralUnitProperty();
		centralUnitDAO.saveOrUpdate(centralUnit);
		String script = "closeCenterLayoutTab('"
				+ SecurityConst.CENTRALUNIT_EDIT_TAB + "')";
		Browser.execClientScript("window.top", script);
	}
}
